#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=3e2+10,INF=0x3f3f3f3f;
int n,e[MAXN][MAXN],match[MAXN],lx[MAXN],ly[MAXN],slack[MAXN];
bool visx[MAXN],visy[MAXN];
bool dfs(int x)
{
	visx[x]=true;
	for(int y=1;y<=n;++y)
	{
		if(visy[y])continue;
		int t=lx[x]+ly[y]-e[x][y];
		if(!t)
		{
			visy[y]=true;
			if(!match[y]||dfs(match[y]))
			{
				match[y]=x;
				return true;
			}
		}
		else slack[y]=min(slack[y],t);
	}
	return false;
}
int KM()
{
	memset(match,0,sizeof(match));
	memset(ly,0,sizeof(ly));
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			lx[i]=max(lx[i],e[i][j]);
	for(int i=1;i<=n;++i)
	{
		memset(slack,0x3f3f3f3f,sizeof(slack));
		while(true)
		{
			memset(visx,0,sizeof(visx));
			memset(visy,0,sizeof(visy));
			if(dfs(i))break;
			int d=INF;
			for(int j=1;j<=n;++j)if(!visy[j])d=min(d,slack[j]);
			for(int j=1;j<=n;++j)
			{
				if(visx[j])lx[j]-=d;
				if(visy[j])ly[j]+=d;
				else slack[j]-=d;
			}
		}
	}
	int ret=0;
	for(int i=1;i<=n;++i)ret+=e[match[i]][i];
	return ret;
}
int main()
{
	while(scanf("%d",&n)==1)
	{
		for(int i=1;i<=n;++i)
			for(int j=1;j<=n;++j)
				scanf("%d",&e[i][j]);
		printf("%d\n",KM());
	}
	return 0;
}
